home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / dino / dino_bot.1 / examples / smoothing / ex4.d < prev    next >
Encoding:
Text File  |  1991-05-02  |  3.6 KB  |  118 lines

  1. /* Copyright, 1990, Regents of the University of Colorado */
  2. /* This program computes a five point smoothing algorithm, just like ex3.d,
  3.  * except that it deals with matrix sizes which are not a multiple of the
  4.  * number of processors.  It uses the include file d "map.c" to do
  5.  * this. */
  6.  
  7. #include "dino.h"
  8.  
  9. #define max(x,y) (x > y ? x : y)
  10. #define min(x,y) (x < y ? x : y)
  11.  
  12. #define M 11
  13. #define N 8
  14. #define P1 3
  15. #define P2 3
  16.  
  17. environment node[P1:id1][P2:id2] {
  18.  
  19. #include "../inc/map.c"
  20.  
  21.                                 /* ==> Includes the map.c include file.  Since
  22.                                        this file contains code, it must be
  23.                                        included within an environment.  See
  24.                                        the listing after example 2.4. */
  25.  
  26.   composite smooth (a, in iter)
  27.   double distributed a[M][N] map FivePt;
  28.   int iter;
  29.  
  30.   {
  31.     int i, j, k;        /* Looping variables */
  32.     map_var a1, a2;
  33.  
  34.     /* Setup map_var's a1 and a2 for the complete data structure A */
  35.     set_map_var (M, P1, id1, 1, 1, &a1);
  36.     set_map_var (N, P2, id2, 1, 1, &a2);
  37.  
  38.                                 /* ==> Illustrates the use of set_map_var
  39.                                        with overlaps (see examples/matvec/ex4.d
  40.                                        for an explanation of set_map_var). */
  41.  
  42.     /* Limit the map_var's to not use the edges of A, which are boundary
  43.      * conditions that don't change */
  44.  
  45.     limit_map_var (1,           /* Minimum data used */
  46.                    M-2,         /* Maximum data used */
  47.                    &a1);        /* Address of the map_var */
  48.  
  49.                                 /* ==> This function, defined in map.c, limits
  50.                                        the map_var a1 to the range <1,M-2>.
  51.                                        This means that the edge data is not
  52.                                        send and/or received when map_var a1
  53.                                        is used.  */
  54.  
  55.     limit_map_var (1, N-2, &a2);
  56.  
  57.     /* Repeat the smoothing process iter times */
  58.     for (i = 0; i < iter; i++) {
  59.  
  60.       /* Send out your data and receive it back again, if not the first
  61.        * iteration */
  62.       if (i != 0) {
  63.         a[<a1.left,a1.right>][<a2.left,a2.right>]# =
  64.           a[<a1.left,a1.right>][<a2.left,a2.right>];
  65.         a[<a1.lover,a1.rover>][<a2.lover,a2.rover>]#;
  66.       }
  67.  
  68.       /* Perform the computation, but only on non-edge elements */
  69.       for (j = a1.left; j <= a1.right; j++)
  70.         for (k = a2.left; k <= a2.right; k++)
  71.           a[j][k] = (a[j][k-1] + a[j][k+1] + a[j-1][k] + a[j+1][k]) / 4;
  72.  
  73.     }
  74.   }
  75. }
  76.  
  77. environment host {
  78.  
  79.   void main ()
  80.  
  81.   {
  82.     double a[M][N];                     /* Input data */
  83.     int iter;                           /* Holds the iteration count */
  84.  
  85.     int i, j;                           /* Looping variables */
  86.  
  87.     /* Set up the initial data for a[][] */
  88.     for (i = 0; i < M; i++)
  89.       for (j = 0; j < N; j++)
  90.         a[i][j] = (i + 1)*(j + 1);
  91.     for (i = 1; i < M - 1; i++)
  92.       for (j = 1; j < N - 1; j++)
  93.         a[i][j] = 0;
  94.  
  95.     /* Set up the variable which will contain the number of iterations */
  96.     iter = 100;
  97.  
  98.     /* Print out the initial data */
  99.     printf ("Initial data for a:\n");
  100.     for (i = 0; i < M; i++) {
  101.       for (j = 0; j < N; j++)
  102.         printf ("%7.2f", a[i][j]);
  103.       printf ("\n");
  104.     }
  105.  
  106.     /* Perform the computation */
  107.     smooth (a[][], iter)#;
  108.  
  109.     /* Printout the results */
  110.     printf ("Result data for a:\n");
  111.     for (i = 0; i < M; i++) {
  112.       for (j = 0; j < N; j++)
  113.         printf ("%7.2f", a[i][j]);
  114.       printf ("\n");
  115.     }
  116.   }
  117. }
  118.